﻿<# TODO
1. 使用
#>

#获取当前执行文件的绝对路径
$currentFilePath = $MyInvocation.MyCommand.Definition;
#获取当前执行文件的父目录的绝对路径
$currentParentFoldPath = Split-Path -Parent $MyInvocation.MyCommand.Definition;

$srcPath = $currentParentFoldPath+"\dbFields.txt"; 
$desPath =  $currentParentFoldPath+"\fileMappingsResult.txt";

function dealLine ($line)
{
    $arr =$line.Split(",") | %{$_.Replace('"','')};
    $fieldName = $arr[0].ToLower();
    $fieldType =  $arr[1];

    if ($fieldType -eq "Date")
    {
          $output += ('add(new FieldMapping_DateTime("{0}"));' -F $fieldName);
          $output += [System.Environment]::NewLine;
    }
    else
    {
        $output += ('add(new FieldMapping("{0}"));' -F $fieldName);
        $output += [System.Environment]::NewLine;
    }
    
    return $output;   
}

$content = Get-Content $srcPath;

$output = "";
foreach ($line in $content)
{
    $output += dealLine($line);
}

#Remove-Item $desPath
$output >> $desPath